<template>
    <div>
        <h2>个人中心</h2>
        <table cellspacing='0' width='80%'>
            <tr >
                <td>用户名</td>
                <td>数量</td>
                <td>手机号</td>
                <td>邮箱</td>
                <td>修改密码</td>
            </tr>
            <tr v-for='i in list' :key="i.id">
                <td>{{i.username}}</td>
                <td>{{i.num}}</td>
                <td>{{i.pthone}}</td>
                <td>{{i.emial}}</td>
                <td><button @click="xiu()">修改密码</button></td>
            </tr>
        </table>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            list:[],
            token:localStorage.getItem('token'),
        }
    },
    methods: {
        update(uid) {
            var password = prompt('请输入新密码')
            if(password == ''){
                this.$toast('新密码不能为空')
                return
            }
            if(password === null){
                this.$toast('取消修改')
                return
            }
            var password1 = prompt('确认密码')
            if(password1 === null){
                this.$toast('取消修改')
                return
            }
            if(password != password1){
                this.$toast('两次密码输入不正确')
                return
            }else(
                axios({
                    url:'http://127.0.0.1:8000/all/',
                    method:'put',
                    params:{
                        token:this.token
                    },
                    data:{
                        'password':password,
                    }
                }).then(resp=>{
                    console.log(res.data)
                    this.$toast(res.data.msg)
                    localStorage.removeItem('username')
                    localStorage.removeItem('token')
                    this.$router.push('head')
                })
            )

        },
    },
    created() {
        axios({
            url:'http://127.0.0.1:8000/all/?token= '+ this.token,
            methond:'get'
        }).then(res=>{
            console.log(res.data)
            this.list = res.data

        })

    }
}
</script>

<style scoped>

</style>
